package com.wl.dzt.sys.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author wl_code@163.com
 * @version 1.0
 * @date 2018/7/5/005
 * @description 动态bean, 链式map
 */
public class DynaBean {
    private Map<String, Object> map = new HashMap<>();

    /**
     * 设置值
     *
     * @param field
     * @param value
     * @return map
     */
    public DynaBean set(String field, Object value) {
        map.put(field, value);
        return this;
    }

    public Object get(String key) {
        return map.get(key);
    }

    /**
     * 删除值
     *
     * @param key
     * @return DynaBean
     */
    public DynaBean remove(String key) {
        map.remove(key);
        return this;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    /**
     * 清除 空值
     *
     * @return
     */
    public DynaBean clearEmptyVal() {
        List<String> keys = new ArrayList<String>();
        for (String key : map.keySet()) {
            if (LogicUtil.isNull(map.get(key))) {
                keys.add(key);
            }
        }
        for (String key : keys) {
            map.remove(key);
        }
        return this;
    }

}
